
import BaseService from "./BaseService";
export default class WXHttpService extends BaseService {

    connect() {
        this.onOpen()
    }
    sendData(message: net.SendMessage) {
        let self = this;
        let protoID = message.sendData.protoId
        let data = message.data;
        window['wx']['request']({
            url: this.url + protoID,
            data: data,
            header: {
                "content-type": "application/octet-stream",
                "accept": "application/octet-stream",
            },
            method: message.sendData.method,
            // dataType: "json",
            responseType: "text",
            success: function (res) {
                if (res.statusCode != 200) {
                    self.onError(message);
                } else {
                    self.onData(res.data);
                }
            },
            fail: function (res) {
                let errMsg = typeof (res.errMsg) == "string" ? res.errMsg : "";
                self.onError(message);
            },
            complete: function (res) { },
        });
    }
    isReady() {
        return true;
    }
}
